<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
  <script type="text/javascript">
      var systemDatabaseColumnTable;
  </script>
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <!-- 当前位置 begin -->
        <div class="row h-home-path">
          <div class="col-md-12 col-sm-12 col-lg-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">导入数据库字段信息</li>
            </ol>
          </div>
        </div>
        <!-- 当前位置 end -->

        <!-- 查询筛选内容 bagin -->
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="form-field-1">字段编码：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="columnCode" name="columnCode" type="text" value=""/>
            </div>
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="form-field-1">字段名称：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="columnName" name="columnName" type="text" value=""/>
            </div>
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" onclick="SystemDatabaseColumnManager.search()" type="button"><i
                      class="fa fa-search">&nbsp;&nbsp;</i>查询
              </button>
              <button class="btn btn-default" type="reset"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>重置</button>
            </div>
          </form>
        </div>

        <!-- 表格 begin -->
        <div class="panel panel-white h-panel">
          <div class="h-table-header">
            <strong>请选择项目编码：</strong>
            <select id="projectId" name="projectId">
              <option value="">--请选择--</option>
              <#list systemProjectInfoList as spl>
              <option value="${spl.id!}">${spl.projectCode}</option>
            </#list>
            </select>
            <label class="required">*</label>
          </div>
          <div class="panel-body">
            <table class="table table-striped table-bordered table-hover text-center" id="systemDatabaseColumn_table"
                   style="width:100%"></table>
          </div>
        </div>
        <!-- 表格 end -->
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->

</div>
<#include "/common/jslib.html">

<script type="text/javascript">
    $(function () {
        var api = frameElement.api;
        var W = api.opener;
        SystemDatabaseColumnManager = {
            init: function () {
                api.button({
                    id: 'importAll',
                    name: '全部导入',
                    callback: SystemDatabaseColumnManager.importAllDataEntry
                });
                api.button({
                    id: 'import',
                    name: '确认导入',
                    callback: SystemDatabaseColumnManager.importDataEntry
                });
                api.button({
                    id: 'cancel',
                    name: '关闭',
                    callback: function () {
                        W.location.reload();
                    }
                });
            },
            search: function () {
                var queryCond = {
                    columnCode: $("#columnCode").val(),
                    columnName: $("#columnName").val()
                };
                systemDatabaseColumnTable.options.queryCond = queryCond;
                var tableId = systemDatabaseColumnTable.options.tableId;
                $(tableId).DataTable().draw();
            },
            addSystemDatabaseColumn: function () {
                window.location.href = "/systemDatabaseColumn/to-form?operation=add";
            },
            deleteSystemDatabaseColumn: function (url, id) {
                var data = {
                    "id": id
                };
                Jmts.deleteItem("确定要删除吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("删除成功");
                      SystemDatabaseColumnManager.search();
                    }
                });
            },
            importDataEntry: function () {

                if ($("input[name='systemDatabaseColumn_select']:checked").length == 0) {
                    Jmts.warnTips("请选择要导入的字段信息");
                    return false;
                }
                var projectId = $("#projectId").val();
                if (projectId == null || projectId == '' || projectId == 'undefined') {
                    Jmts.warnTips("请选择项目编码");
                    return false;
                }
                var dataEntryArray = [];
                $("input[name='systemDatabaseColumn_select']:checked").each(function () {
                    dataEntryArray.push($(this).val());
                });
                var dataEntryStr = dataEntryArray.join(",");
                var data = {
                    dataEntryStr: dataEntryStr,
                    projectId: projectId
                }
                var url = "/systemDataEntry/importDataEntry";
                Jmts.ajaxPost(url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips(result.msg);
                      SystemDatabaseColumnManager.search();
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                });
                return false;
            },
            importAllDataEntry: function () {
                var projectId = $("#projectId").val();
                if (projectId == null || projectId == '' || projectId == 'undefined') {
                    Jmts.warnTips("请选择项目编码");
                    return false;
                }
                var data = {
                    projectId: projectId
                }
                var url = "/systemDataEntry/importAllDataEntry";
                Jmts.ajaxPost(url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips(result.msg);
                      SystemDatabaseColumnManager.search();
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                });
                return false;
            }
        }
        // 执行初始化
        SystemDatabaseColumnManager.init();
    });
</script>
<!-- js -->
<script type="text/javascript">
    (function () {
        // datatable插件
        systemDatabaseColumnTable = new mi.datatable({
            tableId: '#systemDatabaseColumn_table',
            headerList: [
                '选择',
                '数据库字段编码',
                '数据库字段名称',
                '数据库字段类型',
                '数据库字段长度',
                '数据库字段小数位'
            ],
            headerName: [
                'tableRadio',
                'columnCode',
                'columnName',
                'columnTypeCn',
                'columnLength',
                'columnPoint'
            ],
            createdRow: function (row, data, dataIndex) {
                $(row).children('td').eq(1).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(2).attr('style',
                    'text-align:left;');
            },
            ajaxUrl: '/systemDatabaseColumn/listImportSystemDatabaseColumn',
            queryCond: function () {

            },
            columnDefs: [
                {targets: 0, orderable: false}
            ],
            dataSrc: function (data) {
                var newArr = [];
                for (var i in data) {
                    var id = data[i]['id'];
                    var columnCode = data[i]['columnCode'];
                    var columnName = (data[i]['columnName'] == '' || data[i]['columnName'] == null) ? '空' : data[i]['columnName'];
                    var columnType = data[i]['columnType'];
                    var columnLength = (data[i]['columnLength'] == '' || data[i]['columnLength'] == null) ? '0' : data[i]['columnLength'];
                    var columnPoint = (data[i]['columnPoint'] == '' || data[i]['columnPoint'] == null) ? '0' : data[i]['columnPoint'];
                    var operateStr = columnCode + "#" + columnName + "#" + columnType + "#" + columnLength + "#" + columnPoint;
                    var delbtnDtr = mi.markLink({
                        href: "javascript:SystemDatabaseColumnManager.deleteSystemDatabaseColumn('/systemDatabaseColumn/delete','" + id + "');",
                        txt: '删除  ',
                        className: 'js-del-row-btn btn_operate',
                        data: [
                            {id: id}
                        ]
                    });
                    var updatebtnDtr = mi.markLink({
                        href: '/systemDatabaseColumn/to-form?id=' + id + "&operation=edit",
                        txt: '修改',
                        className: 'js-del-row-btn',
                        data: [
                            {id: id}
                        ]
                    });
                    var viewDtr = mi.markLink({
                        href: '/systemDatabaseColumn/to-form?id=' + id + "&operation=view",
                        className: 'js-del-row-btn',
                        txt: '  查看',
                        data: [
                            {id: id}
                        ]
                    });
                    var operateDtr = mi.markLink({
                        href: 'javascript:void(0)',
                        txt: "<input type='checkbox' id='systemDatabaseColumn_select' name='systemDatabaseColumn_select' value='" + operateStr + "'/>",
                        className: 'js-del-row-btn',
                        data: [
                            {id: id}
                        ]
                    });
                    data[i]['tableRadio'] = operateDtr;
                }
                return data;
            }
        });
    })();
</script>
</body>
</html>
